﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;
using T.FAS.Runtime.Base.Dao;
using T.FAS.Runtime.ScheduleJob.SPI;
using T.ServiceComponent.DAC.Service;
using T.ServiceComponent.DataAccessEx.Core;

namespace T.FAS.Runtime.ScheduleJob.Dao
{
    public class SubscriptionNoticeDefinitionDao : DaoService<SubscriptionNoticeDefinition>
    {
        public override string TableName => "FAS_SubscriptionNoticeDefinition";
        public override string IDColumnName => "ID";

        public override List<string> ExceptColumnName
            => DaoUtil.GetExceptionColumn<SysExecuteFrequencyDao>(
                new List<string>
                {
                }
            );
        public SubscriptionNoticeDefinitionDao() : base()
        {
            DBName = "TFAS";
        }
        public override SubscriptionNoticeDefinition ConvertToObject(Dictionary<string, PropertyInfo> columns, DataRow row)
        {
            if (columns.ContainsKey("NoticeScope"))
                columns.Remove("NoticeScope");
            var data = base.ConvertToObject(columns, row);

            data.NoticeScope = (NoticeScope)Enum.Parse(typeof(TriggerType), Convert.ToString(row["NoticeScope"]));
            return data;
        }
        public override Dictionary<string, object> GetDataMapping(SubscriptionNoticeDefinition data)
        {
            var mapping = base.GetDataMapping(data);
            mapping.Remove("NoticeScope");
            mapping.Add("NoticeScope", (int)data.NoticeScope);
            return mapping;
        }
        public override Dictionary<string, PropertyInfo> GetColumns()
        {
            return base.GetColumns();
        }

        public SubscriptionNoticeDefinition GetSubscriptionNoticeDefinitionByID(string id)
        {
            var data = base.Get(id);
            return data as SubscriptionNoticeDefinition;
        }
        public List<SubscriptionNoticeDefinition> GetSubscriptionNoticeDefinitions(UserDefineQueryFilter filter)
        {
            //string queryFilter = " IsEnable = 1";
            //var result = base.GetObjectsByFilter(queryFilter);
            //var list = new List<SubscriptionNoticeDefinition>();
            //if (result != null && result.Count > 0)
            //{
            //    result.ForEach(r => list.Add(r as SubscriptionNoticeDefinition));
            //}
            //return list.OrderBy(x => x.SortOrder).ToList();
            var dt = base.GetByFilter($" IsEnable = 1");
            var metadatas = DaoUtil.ConvertToEntity<SubscriptionNoticeDefinition>(dt, this.ExceptColumnName);
            InternationalDaoTools.FillInternationalFields(metadatas, dt, this);
            return metadatas;
        }
    }
}
